<template>
  <div class="toast">{{ msg }}</div>
</template>

<script>
import { reactive } from "vue";
export default {
  name: "Toast",
  props: ["msg"],
};
export const useToastEffect = () => {
  const toastData = reactive({
    showToast: false,
    toastMsg: "",
  });
  const showToast = (message) => {
    toastData.showToast = true;
    toastData.toastMsg = message;
    setTimeout(() => {
      toastData.showToast = false;
      toastData.toastMsg = "";
    }, 2000);
  };
  return { toastData, showToast };
};
</script>

<style lang="scss" scoped>
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.2rem;
  font-size: 0.16rem;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.35);
  border-radius: 0.05rem;
}
</style>
